<?php

class Admin_Model_Project extends Zend_Db_Table_Abstract
{
    protected $_name = 'project';
    public function getAllData(){
    	$query = $this->select()
                        ->from($this->_name);
    	return $this->fetchAll($query);
    }
    public function getAllData1(){        
        $query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('p'=>$this->_name))
                        ->joinLeft(array('d'=>'district'),'p.districtid = d.districtid', array('d.name as districtName'))
                        ->joinLeft(array('pv'=>'province'),'d.provinceid = pv.provinceid', array('pv.provinceid as provinceId','pv.name as provinceName'));                      
        return $this->fetchAll($query);        
    }
    public function getDataById ($proId){
    	$query = $this->select()
                        ->from($this->_name, array('projectName'))
                        ->where('projectId = ?',(int)$proId);
        $result= $this->fetchRow($query);
        return $result['projectName'];
    }
    public function getDataByProjectId($proId){
        $query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('p'=>$this->_name))
                        ->joinLeft(array('d'=>'district'),'p.districtid = d.districtid', array('d.name as districtName'))
                        ->joinLeft(array('pv'=>'province'),'d.provinceid = pv.provinceid', array('pv.provinceid as provinceId','pv.name as provinceName'))
                        ->where('projectId = ?',(int)$proId);
        return $this->fetchRow($query);
    }
    public function getDataByDistrictId($districtId){
        $query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('p'=>$this->_name))
                        ->joinLeft(array('d'=>'district'),'p.districtid = d.districtid', array('d.name as districtName'))
                        ->joinLeft(array('pv'=>'province'),'d.provinceid = pv.provinceid', array('pv.provinceid as provinceId','pv.name as provinceName'))
                        ->where('p.districtId = ?',(int)$districtId);
        return $this->fetchAll($query);
    }        
    public function addData($data){        
        $data = array('projectId'=>$data['projectId'],
                'projectName'=> $data['projectName'],
                'districtId'  => $data['districtId']);                  
        $idAdd = $this->insert($data);                                                                                                                                                                                
        return $idAdd;
    }
    public function updateData($proId = '',$data){        
        $data = array('projectName'=> $data['projectName'],
                'districtId'  => $data['districtId']);                
        return $this->update($data, 'projectId = '.(int)$proId);
    }            
    public function deleteData($id){        
        $this->delete('projectId = '.(int)$id);
    }
}

